package study.linux.laptrinhlinux.postgresql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.*;

public class PostgreSQLTest {

	/**
	 * PostgreSQLTest
	 *
	 * @author Morizo
	 * @param args
	 */
	public static void main(String[] args) {
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			System.out.println("1");
			Class.forName("org.postgresql.Driver");
			System.out.println("2");
			con = DriverManager
					.getConnection("jdbc:postgresql://153.122.19.224:5432/testdb",
							"test", "test");
			stmt = con.createStatement();
			System.out.println("3");
			String sqlStr = "SELECT * FROM testtable";
			rs = stmt.executeQuery(sqlStr);
			System.out.println("4");
			while (rs.next()) {
				System.out.println("5");
				int id = rs.getInt("id");
				String title = rs.getString("title");

				System.out.println(id + " " + title);
			}



		} catch (Exception e) {
			System.out.println("6");
			System.out.println(e.toString());
			// TODO: handle exception
		} finally {
			try {
				rs.close();
				stmt.close();
				con.close();
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}
	}
}
